package Structure.HashTable;

/**
 * @author wang'ji'cheng
 * @date 2025/7/25
 * 节点类
 */


public class HashTable {

    //节点类
    static class Entry {
        //哈希码
        int hashCode;
        //键
        Object key;
        //值
        Object value;
        //指针
        Entry next;

        public Entry(Object key, int hashCode, Object value) {
            this.key = key;
            this.hashCode = hashCode;
            this.value = value;
        }
    }

    Entry[] entries = new Entry[16];
    int size = 0;
    //为什么数组长度定义为2的n次方，为了进行位运算，元素存储在数组的索引=hash &（数组长度-1）

    //获取元素
    Object get(int hashCode, Object key) {
        //获取存入数组的索引
        int index = hashCode & (entries.length - 1);
        if (entries[index] == null) {
            return null;
        } else {
            //获取链表的头结点
            Entry p = entries[index];
            //遍历链表
            while (p != null) {
                if (p.key.equals(key)) {
                    return p.value;
                }
                p = p.next;
            }
            return null;
        }
    }

    //添加元素(没有则添加，有则更新)
    void put(int hashCode, Object key, Object value) {

    }

    //删除元素
    void delete(int hashCode, Object key) {

    }


}
